﻿<%@page import="com.hh.bss.util.StringHelper" %>
<%
  String pnNbr=request.getParameter("pnNbr");    
  String custId=request.getParameter("custId");    
  String jobId=request.getParameter("jobId");    
  if (StringHelper.isEmpty(pnNbr)) pnNbr="";
  if (StringHelper.isEmpty(custId)) custId="0";
  if (StringHelper.isEmpty(jobId)) jobId="0";
  
%>  

	
<!DOCTYPE html>  
<html>  
<head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
    <meta name="keywords" content="账单发票">  
    <meta name="description" content="账单发票">  
    <title>账单发票管理</title>  
    
    <%@ include file="/WEB-INF/inc/default.jsp"%>
    <jsp:include page="/WEB-INF/inc/dic.jsp"/>

</head> 
<script>

  var jobId=<%=jobId%>;
  var custId=<%=custId%>;
  var pnNbr="<%=pnNbr%>";
</script>  
<body>  
    
      
    <table id="dg"  style="height:200px"  
            url="/project/accountInvoice/list.do?pnNbr=<%=pnNbr%>"  
            toolbar="#toolbar" pagination="true"  
            rownumbers="true" fitColumns="true" loadMsg="正在查询,请稍候..." singleSelect="false">  

    </table>  
    <div id="toolbar">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add()">新增</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit()">修改</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deletes()">删除</a>  
        
    </div>  
    <!-- edit form窗体（开始） -->  
    <div id="dlg" style="display:none;">  
        <!--    
        <form id="fm" method="post" novalidate>  
        	  	  	 <input type="hidden" name="id" > 
        	  	  	 <input type="hidden" name="pnNbr" > 
	        		     <input type="hidden" name="status" >  
	        		     <div class="fitem">  
                     <label style="width:100px">发票编号<font color="red">*</font>:</label>                       
                     <input name="nbr" class="easyui-numberbox easyui-validatebox"  required="true">                       
                   </div>	        		     
	        		     <div class="fitem">  
                     <label style="width:100px">发票金额<font color="red">*</font>:</label>                       
                     <input name="amount" class="easyui-numberbox easyui-validatebox"  required="true">                       
                   </div>	        		     
	        		     <div class="fitem">  
                     <label style="width:100px">货币单位<font color="red">*</font>:</label>                                                                 
                     <input class="easyui-combobox" itemId="currency"  required="true" name="currency" style="width:200px;"  data-options="data:__getConstantCategory('MoneyType'),valueField:'code', textField:'value', multiple:false,panelHeight:'auto',mode:'remote' ">
                   </div> 
        	  	   	  	        	  	   	
	        		     <div class="fitem">  
                     <label style="width:100px">寄送日期:</label>                       
                     <input name="sendDtString" data-options="formatter:formateDate"  class="easyui-datebox">                       
                   </div>  	        		     
	        		     <div class="fitem">  
                     <label style="width:100px">发送人</label>                                                                 
                     <input class="easyui-combobox" itemId="sender"  name="sender" style="width:200px;"  data-options="data:'/auth/systemUser/userlist.do',valueField:'account', textField:'name', multiple:false,panelHeight:'auto',mode:'remote' ">
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">客户联系人</label>                       
                     
                     <input class="easyui-combobox" itemId="reciever"  name="reciever" style="width:200px;"  data-options="data:'/customer/customerContacter/customercontactlist.do',valueField:'cvId', textField:'cvName', multiple:false,panelHeight:'auto',mode:'remote' ">
                   </div>	        		     
	        		     <div class="fitem">  
                     <label style="width:100px">快递单号:</label>                                            
                     <input name="expressId" class="easyui-box">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">收到日期:</label>                       
                     <input name="recieveDt" data-options="formatter:formateDate"  class="easyui-datebox">                       
                   </div>  	        		     
	        		     <div class="fitem">  
                     <label style="width:100px">备注:</label>                                            
                     
                     <textarea name="comment" style="width:300px;height:80px" ></textarea>                     
                   </div> 
	        		      	        		     
        </form>  
        <div  style="text-align:center">  
          <a href="javascript:void(0)" id="btn-save" class="easyui-linkbutton" iconCls="icon-ok" ">Save</a>  
          <a href="javascript:void(0)" id="btn-close" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>  
        </div>
        -->
    </div>  
    <!-- edit form窗体（结束） -->  
    <!-- query form窗体(开始) -->  
    <div id="dlg_query" style="display:none;">  
    	  <!--
        <div class="ftitle">账单发票</div>  
        <form id="fm_query" method="post" novalidate>  
            
              
	        		     <div class="fitem">  
                     <label style="width:100px">PN编号:</label>                                            
                     <input name="pnNbr" class="easyui-box">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">发票编号:</label>                       
                     <input name="nbr" class="easyui-numberbox">                       
                   </div>	        		     	        		    
        	  	   	 <div class="fitem">  
                     <label style="width:100px">状态:</label>                                                                 
                     <input class="easyui-combobox" name="status" style="width:200px;"  data-options="data:__getConstantCategory('AccountInvoiceStatus'),valueField:'code', textField:'value', multiple:false,panelHeight:'auto',mode:'remote' ">                     
                   </div>      	
	        		     <div class="fitem">  
                     <label style="width:100px">寄送时间:</label>                       
                     <input name="sendDt" data-options="formatter:formateDate" class="easyui-datebox">                         	
                   </div>  	        		     
	        		     <div class="fitem">  
                     <label style="width:100px">发送人:</label>                                            
                     <input name="sender" class="easyui-box">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">接收人:</label>                       
                     <input name="reciever" class="easyui-numberbox">                       
                   </div>	        		     
	        		     <div class="fitem">  
                     <label style="width:100px">快递单号:</label>                                            
                     <input name="expressId" class="easyui-box">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">收到时间:</label>                       
                     <input name="recieveDt" data-options="formatter:formateDate" class="easyui-datebox">                         	
                   </div>  	        		     
	        		     <div class="fitem">  
                     <label style="width:100px">备注:</label>                                            
                     <input name="comment" class="easyui-box">                       
                   </div> 
	        		     
              
        </form>
        <div  style="text-align:center">  
          <a href="javascript:void(0)" id="btn-query" class="easyui-linkbutton" iconCls="icon-ok" ">查询</a>  
          <a href="javascript:void(0)" id="btn-query-close" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>  
        </div>  
        -->
    </div> 
    <!-- query form窗体(结束) -->  
    
    <script type="text/javascript">  
        var url;  
        
        var url;  
        var optWin = $.window({
		       		 title:"新增账单发票",
		       		 tplRef:"dlg",//这个属性指定模板id
		       		 height:450,		       		 
		       		 width:500,	
		       		 closed:true,		       		 
		       		 onComplete:function(){
		       		 	  //窗口里面的初始化,最好是在这个事件里面进行
		       		 	  var curWin=this;
		       		 	  var doForm=curWin.find('#fm');
		       		 	  curWin.doForm=doForm;
		       		 	  this.find("#btn-close").click(function(){		       		 	  	
		       		 	  	   curWin.window('close');
		       		 	  });
		       		 	  this.find("#btn-save").click(function(){		       		 	  	
		                 		  if (!doForm.form('validate')) return;
		                 		  
		                 		  doForm.form('submit',{  
                            url: curWin.url,  
                            onSubmit: function(){                              	  
                                return doForm.form('validate');  
                            },  
                            success: function(result){  
                                var result = eval('('+result+')');                      
                                if (result.success == true){  
                                    //$.messager.alert('信息',result.msg,'info');  
                                    alert(result.msg);
                                    curWin.window('close');
                                    curWin.openWin.reload();
                                    
                                } else {  
                                    //$.messager.alert('错误',result.msg,'error');
                                    alert(result.msg);
                                }  
                            }  
                       }); 		 
		              });
		       		   
		       		 }
		    });
		    
		    var queryWin = $.window({
		       		 title:"账单发票查询",
		       		 tplRef:"dlg_query",//这个属性指定模板id
		       		 height:200,		       		 
		       		 closed:true,		       		 
		       		 onComplete:function(){
		       		 	  //窗口里面的初始化,最好是在这个事件里面进行
		       		 	  var curWin=this;
		       		 	  var doForm=curWin.find('#fm_query');
		       		 	  curWin.doForm=doForm;
		       		 	  this.find("#btn-query-close").click(function(){		       		 	  	
		       		 	  	   curWin.window('close');
		       		 	  });
		       		 	  this.find("#btn-query").click(function(){
		       		 	  			                 		  
		                 		 //var formdata=$('#fm_query').formToArray(); 
		                 		 curWin.window('close');
		                 		 var formdata=curWin.find('#fm_query').formToArray();   		 
		                 		 curWin.openWin.query(formdata);
		              });
		       		   
		       		 }
		    });
        
        
        function add(){         	                        
            optWin.window('open'); 
            optWin.openWin=window;    
            optWin.url='/project/accountInvoice/save.do';  
            optWin.doForm.form('clear');
            optWin.window('setTitle','新增账单发票');
            optWin.doForm.find('input[name="pnNbr"]').attr("value",pnNbr);
            optWin.doForm.find('input[name="status"]').attr("value",'0');
            optWin.doForm.find('input[itemId="currency"]').combobox("setValue","RMB");
            optWin.doForm.find('input[itemId="sendDt"]').datetimebox("setValue",_nowdatetime());
            optWin.doForm.find('input[itemId="sender"]').combobox("setValue",_getUsername());
            optWin.doForm.find('input[itemId="reciever"]').combobox("reload",'/customer/customerContacter/list.do?custId='+custId);
            
        }  
        function doEdit(id){  
        	 optWin.window('open');
		             optWin.doForm.form('clear');
		             optWin.url='/project/accountInvoice/update.do'; 
		             optWin.doForm.find('input[itemId="reciever"]').combobox("reload",'/customer/customerContacter/list.do?custId='+custId);
		             optWin.doForm.form('load','/project/accountInvoice/get.do?id='+id);   
		             optWin.openWin=window;
		             optWin.window('setTitle','修改账单发票');
        }	
        function edit(){  
            //var row = $('#dg').datagrid('getSelected');  
            var rows = $('#dg').datagrid('getSelections');
            if (!rows||rows.length==0){
            	 $.messager.alert('提示','请选择要修改的行','info');
            	 return;
            }
            if (!rows||rows.length>1){
            	 $.messager.alert('提示','不能选择多行','info');
            	 return;
            }
            if (rows){  
                 
		             doEdit(rows[0].id);
            }  
        }  
        function save(){          	   
        	  if (!$('#fm').form('validate')) return; 
            $('#fm').form('submit',{  
                url: url,  
                onSubmit: function(){  
                    return $(this).form('validate');  
                },  
                success: function(result){  
                    var result = eval('('+result+')');                      
                    if (result.success == true){  
                        $.messager.alert('信息',result.msg,'info');  
                        $('#dlg').dialog('close');      // close the dialog  
                        $('#dg').datagrid('reload');    // reload the user data  
                    } else {  
                        $.messager.alert('错误',result.msg,'error');
                    }  
                }  
            });  
        }  
        function deletes(){  
            var row = $('#dg').datagrid('getSelected');  
            
            var rows = $('#dg').datagrid('getSelections');  

            if (!rows||rows.length==0){
            	 $.messager.alert('提示','请选择要删除的行','info');
            	 return;
            }
            if (rows){  
                $.messager.confirm('重要提示','确定要删除?',function(r){  
                    if (r){  
                        $.post('/project/accountInvoice/delete.do',{ids:getRecordArray(rows,'id').join(',')},function(result){  
                            if (result.success){  
                                $('#dg').datagrid('reload');    // reload the user data  
                            } else {  
                                 
                                $.messager.alert('错误',result.errorMsg,'error'); 
                            }  
                        },'json');  
                    }  
                });  
            }  
        }  
        function reload(){        	
        	  $('#dg').datagrid('reload');
        }
        function find(){  
              
                //$('#dlg_query').dialog('open').dialog('setTitle','查询');  
                
                //url = '/project/accountInvoice/list.do';  
                 queryWin.window('open');   
                 queryWin.openWin=window; 
              
        } 
        	
        function query(formdata){  
                
                $('#dg').datagrid({
	                  queryParams: array2json(formdata)
                });
              
        }
        
        //生成grid的字段,需要字典的自动转换
        $('#dg').datagrid({
        	   columns:[[
        	   	
        	   	   {field:'pnNbr',title:'账单编号', width:100}
        	   	   ,{field:'nbr',title:'发票编号', width:100}
        	   	   ,{field:'amount',title:'发票金额', width:100}
        	   	   ,{field:'currency',title:'货币单位', width:100,hidden:true}
        	   	   ,{field:'status',title:'状态', width:100,
        	   		      formatter: function(value,row,index){
        	   		      	return __getConstantCategoryCodeValue('AccountInvoiceStatus', value);
        	   		      }
        	   	     }
        	   	   ,{field:'sendDt',title:'寄送日期', width:100,
        	   	   	formatter: function(value,row,index){
        	   		      	
        	   		      	if (value && value.length >= 10)
														return value.substring(0, 10)
        	   		      }
        	   	   	}
        	   	   ,{field:'sender',title:'发送人', width:100}
        	   	   ,{field:'reciever',title:'接收人', width:100}
        	   	   ,{field:'expressId',title:'快递单号', width:100}
        	   	   ,{field:'recieveDt',title:'收到日期', width:100}
        	   	   ,{field:'comment',title:'备注', width:100,hidden:true}
        	   	   ,{field:'creator',title:'创建人', width:100}
        	   	   ,{field:'createDt',title:'创建时间', width:100}
        	   	   ,{field:'modifier',title:'修改人', width:100}
        	   	   ,{field:'modifiedDt',title:'修改时间', width:100}
        	   	
        	   	
        	   ]]
        	   ,onDblClickRow: function(rowIndex, rowData){
        	    	//$('#dlg').dialog('open').dialog('setTitle','修改账单发票');                  
                //$('#fm').form('load','/project/accountInvoice/get.do?id='+rowData.id);  
                //url = '/project/accountInvoice/update.do';        	    	
                doEdit(rowData.id);
        	    }
        }); 
        //完成-生成grid的字段
        
        
        
    </script>  
     
     

     
     
     
</body>  
</html>